package net.javalib.flickr.search.activities;

import net.javalib.flickr.search.DownloadInfo;
import net.javalib.flickr.search.R;
import net.javalib.flickr.search.flickr.FlickrImage;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Simple activity that displays an image.
 */
public class DetailsActivity extends AbstractBaseActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.details);
		
		Intent i = getIntent();
		long imageId = i.getLongExtra("imageId", -1);
		if (imageId == -1) {
			finish();
			System.err.println("imageId missing.");
			return;
		}

		FlickrImage image = app.getImage(imageId);
		if (image == null) {
			finish();
			System.err.println("image missing : "+imageId);
			return;
		}
		
		TextView title = (TextView) findViewById(R.id.details_title);
		title.setText(image.title);
		
		ImageView imageView = (ImageView) findViewById(R.id.details_image);
		imageView.setImageBitmap(app.getImageBitmap(DownloadInfo.getCacheKey(image, false)));
		
	}
	
	public static Intent createIntent(Context context, FlickrImage image) {
		Intent i = new Intent(context, DetailsActivity.class);
		i.putExtra("imageId", image.id);
		return i;
	}
	
}
